Get Event Details
Description
The get_event_details
function retrieves details for a specific event based on the provided event ID. It sends a GET request to the web service and returns a WebServiceResult
object containing the response code, response string, and parsed JSON data.
Function Signature:
def get_event_details(ws_config: WebServiceConfig, event_id: int) -> WebServiceResult:
Parameters
- ws_config (WebServiceConfig): Configuration for the web service connection.
- event_id (int): The ID of the event to retrieve details for.
Returns
- WebServiceResult: A result object containing:
http_response_code
: The response code from the web service.http_response_string
: The response string from the web service.json_data
: The parsed JSON response from the web service, orNone
if there was an error.code
: A status code (0 for success, -1 for failure).description
: A description of any error that occurred.
Example Usage
ws_config = WebServiceConfig(base_url="https://api.actionstreamer.com")
event_id = 456
result = get_event_details(ws_config, event_id)
print(result.http_response_code)
print(result.json_data)
Behavior
- The function sends a GET request to the web service to fetch details for the event with the given
event_id
. - The response is parsed into a
WebServiceResult
object, which contains the response code, response string, and parsed JSON data. - If a
json.JSONDecodeError
occurs, it is silently ignored, as the function can proceed without it. - If any other errors occur, they are caught, and an exception description is added to the result.
Error Handling
- json.JSONDecodeError: If there is an error parsing the JSON response, it is ignored.
- General Exception: Any errors during the request or JSON processing will be caught, and the error description will be included in the result.
- Exception Information: The function prints the filename and line number for easier debugging when an exception is encountered.